package com.shujia.spark.mllib

import org.apache.spark.ml.feature.LabeledPoint
import org.apache.spark.ml.linalg
import org.apache.spark.ml.linalg.Vectors

object Demo3DataType {
  def main(args: Array[String]): Unit = {

    /**
      * 稠密向量
      *
      */

    val denseVertor: linalg.Vector = Vectors.dense(Array(1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 4.0))

    println(denseVertor)


    /**
      * 稀疏向量: 如果数据中有大量的0 ,使用稀疏效率可以节省空间
      *
      */
    val sparseVector: linalg.Vector = Vectors.sparse(9, Array(0, 1, 7, 8), Array(1.0, 2.0, 3.0, 4.0))

    println(sparseVector)


    //相互转换
    println(sparseVector.toDense)


    /**
      *
      * 标记数据：LabeledPoint
      */


    val pos = LabeledPoint(1.0, Vectors.dense(1.0, 0.0, 3.0))


    println(pos)



  }

}
